/**
 * 检查娱乐城相关表结构的脚本
 */

const mysql = require('mysql2/promise');

const DB_CONFIG = {
    host: '43.143.253.188',
    port: 3306,
    user: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs',
    timezone: '+08:00'
};

async function checkCasinoTables() {
    let connection;

    try {
        console.log('🔌 正在连接数据库...');
        connection = await mysql.createConnection(DB_CONFIG);
        console.log('✅ 数据库连接成功！\n');

        // 检查娱乐城相关表
        const tables = [
            'casino_rounds',
            'casino_dice_bet',
            'casino_chibi_bet',
            'casino_rock_paper_scissors',
            'casino_config',
            'casino_operation_log',
            'casino_ranking'
        ];

        for (const table of tables) {
            try {
                console.log(`🔍 检查表: ${table}`);
                const [columns] = await connection.execute(`DESCRIBE ${table}`);
                console.log(`📋 ${table}表字段:`);
                columns.forEach(col => {
                    console.log(`   • ${col.Field}: ${col.Type} ${col.Null === 'NO' ? 'NOT NULL' : 'NULL'} ${col.Key ? `(${col.Key})` : ''}`);
                });
                console.log('');
            } catch (error) {
                console.log(`❌ 表 ${table} 不存在或无法访问: ${error.message}\n`);
            }
        }

        // 检查是否有其他相关的表
        console.log('🔍 检查所有以casino_开头的表...');
        const [casinoTables] = await connection.execute(`
            SELECT TABLE_NAME 
            FROM information_schema.TABLES 
            WHERE TABLE_SCHEMA = 'nextjs' 
            AND TABLE_NAME LIKE 'casino_%'
            ORDER BY TABLE_NAME
        `);

        if (casinoTables.length > 0) {
            console.log('📋 找到的casino_表:');
            casinoTables.forEach(table => {
                console.log(`   • ${table.TABLE_NAME}`);
            });
        } else {
            console.log('❌ 没有找到casino_开头的表');
        }

    } catch (error) {
        console.error('❌ 检查过程中发生错误:', error.message);
        console.error(error.stack);
    } finally {
        if (connection) {
            await connection.end();
            console.log('\n🔌 数据库连接已关闭');
        }
    }
}

// 运行检查脚本
if (require.main === module) {
    checkCasinoTables().catch(console.error);
}

module.exports = { checkCasinoTables }; 